<template>
  <div>
    <!--小程序装修配置-->
    <el-table v-loading="loading" :data="list" :border="true">
      <el-table-column
        label="模板号"
        min-width="30"
        prop="configType"
        align="center"
      >
        <template #default="props">
          <el-input
            @change="UpdateFn(props.row)"
            v-model="props.row.configType"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="模板名称"
        min-width="80"
        prop="configName"
        align="center"
      >
        <template #default="props">
          <el-input
            @change="UpdateFn(props.row)"
            v-model="props.row.configName"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="版本号"
        min-width="80"
        prop="configValue"
        align="center"
      >
        <template #default="props">
          <el-input
            @change="UpdateFn(props.row)"
            v-model="props.row.configValue"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="配置内容"
        min-width="200"
        prop="remark"
        align="center"
      >
        <template #default="props">
          <el-input
            @change="UpdateFn(props.row)"
            v-model="props.row.remark"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="120" align="center">
        <template #default="scope">
          <el-button type="text" @click="UpdateFn(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { getCurrentInstance } from "@vue/runtime-core";

import { appletsRen, editAppletsRen } from "@/api/oam/basic.js";
const { proxy } = getCurrentInstance();
const list = ref([]);
const data = reactive({
  form: {},
});
const { form } = toRefs(data);
// initData();
async function initData() {
  let res = await appletsRen();
  list.value.push(res.data);
}

async function UpdateFn(row) {
  form.value = row;
  if (
    form.value.configName === "" ||
    form.value.configValue === "" ||
    form.value.remark === ""
  ) {
    return initData();
  }
  let res = await editAppletsRen(form.value);
  if (res.code === 200) {
    proxy.$modal.msgSuccess("修改成功");
    list.value = [];
  } else {
    proxy.$modal.msgError("操作失败");
  }
  initData();
}
</script>

<style scoped></style>
